package com.kaili.basic.service.impl;

import com.kaili.basic.pojo.entity.BaseRouteLine;
import com.kaili.basic.pojo.entity.BaseRouteMenu;
import com.kaili.basic.mapper.BaseRouteLineMapper;
import com.kaili.basic.service.BaseRouteLineService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangjl
 * @Type BaseRouteLineServiceImpl
 * @Desc 杭州凯立通信有限公司
 * @Date 2018年05月30日
 */
@Service
public class BaseRouteLineServiceImpl implements BaseRouteLineService {

    @Autowired
    private BaseRouteLineMapper baseRouteLineMapper;

    @Override
    public boolean addRouteLine(BaseRouteLine baseRouteLine) {
        baseRouteLine.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
        baseRouteLine.setCreateTime(new Date());
        int flag = baseRouteLineMapper.insertRouteLine(baseRouteLine);
        if (flag >= 0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean addRouteMenu(BaseRouteMenu routeMenu) {
        routeMenu.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
        routeMenu.setCreateTime(new Date());
        int flag = baseRouteLineMapper.addRouteMenu(routeMenu);
        if (flag >= 0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public BaseRouteMenu getByMenuName(String routeMenuName) {
        return baseRouteLineMapper.getByMenuName(routeMenuName);
    }


    @Override
    public int updateRouteLine(BaseRouteLine baseRouteLine) {
        baseRouteLine.setModifyBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
        baseRouteLine.setModifyTime(new Date());
        return baseRouteLineMapper.updateRouteLine(baseRouteLine);
    }

    @Override
    public void deleteRouteLine(Integer routeId) {
        Map<String, Object> map = new HashMap();
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        if (uid != null) {
            map.put("modifiedBy", uid.longValue());
            map.put("routeId",routeId);
            baseRouteLineMapper.deleteRouteLine(map);
        }
    }

    @Override
    public int deleteRouteMenu(Integer id) {
        return baseRouteLineMapper.deleteRouteMenu(id);
    }

    @Override
    public BaseRouteLine getByRouteId(Integer routeId) {
        return baseRouteLineMapper.getByRouteId(routeId);
    }

    @Override
    public List<BaseRouteLine> getRouteLineList(Integer id) {
        return baseRouteLineMapper.getRouteLineList(id);
    }

    @Override
    public List<BaseRouteLine> listRouteLine() {
        return baseRouteLineMapper.listRouteLine();
    }

    @Override
    public List<BaseRouteLine> queryRouteLineMap(Map<String, Object> map) {
        return baseRouteLineMapper.queryRouteLineMap(map);
    }

    @Override
    public BaseRouteLine routeLineMap(Map map) {
        return baseRouteLineMapper.routeLineMap(map);
    }
}
